package com.flashflexpro.flexdirector.model{
    import mx.collections.ArrayCollection;

    [Bindable]
    [RemoteClass]
    public class DtoActCheck extends NameAndComment{


        public function DtoActCheck(){
            name = "Unnamed Check";
        }

        /**
         * all the properties when recording
         */
        [ArrayElementType("com.flashflexpro.flexdirector.model.CodeStringValue")]
        public var allProperties:ArrayCollection = new ArrayCollection();

        /**
         * asserts need to be compared
         */
        [ArrayElementType("com.flashflexpro.flexdirector.model.CodeStringValue")]
        public var asserts:ArrayCollection = new ArrayCollection();


        override public function copyInto( parent:NameAndComment, newType:Class ):NameAndComment{
            var rt:DtoActCheck = super.copyInto( parent, DtoActCheck ) as DtoActCheck;
            rt.allProperties = cloneAC( allProperties );
            rt.asserts = cloneAC( asserts );
            return rt;
        }

        private function cloneAC( toclone:ArrayCollection ):ArrayCollection{
            var values:ArrayCollection = new ArrayCollection();
            for( var i:int; i < toclone.length; i ++ ){
                values.addItem( ( toclone.getItemAt( i ) as CodeStringValue).clone() );
            }
            return values;
        }

        public function getAssertByProperty( propertyName:String):CodeStringValue{
            for( var j:int = asserts.length - 1; j >= 0; j-- ){
                var csv:CodeStringValue = asserts.getItemAt( j ) as CodeStringValue;
                if( csv.desc.name == propertyName){
                    return csv;
                }
            }
            return null;
        }
        public function delAssert( propertyName:String ):Boolean{
            for( var j:int = asserts.length - 1; j >= 0; j-- ){
                var csv:CodeStringValue = asserts.getItemAt( j ) as CodeStringValue;
                if( csv.desc.name == propertyName){
                    asserts.removeItemAt( j );
                    return true;
                }
            }
            return false;
        }

        public function addAsset( ast:CodeStringValue ):void{

                var addPosition:uint = 0;
                for( var j:int = asserts.length - 1; j >= 0; j-- ){
                    var csv:CodeStringValue = asserts.getItemAt( j ) as CodeStringValue;
                    if( csv.desc.name == ast.desc.name ){
                        asserts.removeItemAt( j );
                        addPosition = j;
                        break;
                    }
                }

                asserts.addItemAt( ast, addPosition );
        }

    }
}